<?php
// +----------------------------------------------------------------------
// | author: thinkphp
// +----------------------------------------------------------------------

namespace app\adminapi\lists\user;

use app\adminapi\lists\BaseAdminDataLists;
use app\common\enum\user\UserTerminalEnum;
use app\common\lists\ListsExcelInterface;
use app\common\lists\ListsSearchInterface;
use app\common\lists\ListsSortInterface;
use app\common\model\user\User;


/**
 * 用户列表
 * Class UserLists
 * @package app\adminapi\lists\user
 */
class UserLists extends BaseAdminDataLists implements ListsExcelInterface, ListsSearchInterface
{
    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author admin
     * @date 2025/04/23 11:42
     */
    public function setSearch(): array
    {
        return [
            '=' => ['user_type', 'travel_agency_id', 'is_disable'],
            '%like%' => ['real_name', 'account'],
        ];
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author admin
     * @date 2025/04/23 11:42
     */
    public function lists(): array
    {
        return User::where($this->searchWhere)
            ->append(['travel_agency_name','is_disable_value','user_type_value','sex_value','driver','driver_status'])
            ->field(['id', 'user_type', 'travel_agency_id', 'avatar', 'real_name', 'nickname', 'account', 'mobile', 'sex', 'is_disable', 'login_ip', 'login_time', 'multipoint_login', 'user_money'])
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取数量
     * @return int
     * @author admin
     * @date 2025/04/23 11:42
     */
    public function count(): int
    {
        return User::where($this->searchWhere)->count();
    }


    /**
     * @notes 导出文件名
     * @return string
     * @author admin
     * @date 2025/04/23 11:42
     */
    public function setFileName(): string
    {
        return '用户列表';
    }


    /**
     * @notes 导出字段
     * @return string[]
     * @author admin
     * @date 2025/04/23 11:42
     */
    public function setExcelFields(): array
    {
        return [
            'sn' => '用户编号',
            'nickname' => '用户昵称',
            'account' => '账号',
            'mobile' => '手机号码',
            'channel' => '注册来源',
            'create_time' => '注册时间',
        ];
    }

}